﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DGRobot
{
    public class RouteHelper
    {
        static Dictionary<string,Form> forms=new Dictionary<string, Form>(); 
        public static Form GetForm(string key,Func<Form> action)
        {
            if (forms.ContainsKey(key))
                return forms[key];
            if (action == null) return null;
            forms[key] = action();
            return forms[key];
        }

        private Form _currentForm;
        private Form _lastForm;
        public void GoForm(Form form)
        {
            _lastForm = _currentForm;
            _lastForm.Hide();
            _currentForm = form;
            _currentForm.Show();
        }

        public void GoPrevForm()
        {
            var temp = _lastForm;
            _lastForm = _currentForm;
            _lastForm.Hide();
            _currentForm = temp;
            _currentForm.Show();
        }
    }
}
